package com.jcwx.game.socket.codex;

import java.util.List;

import org.apache.mina.util.byteaccess.ByteArray;

public class DataType {
	/**
	 * 字符�?
	 */
	public static final int STRING = 0;
	/**
	 * 布尔�?
	 */
	public static final int BOOLEAN = 1;
	/**
	 * 1字节数字
	 */
	public static final int BYTE = 2;
	/**
	 * 16位有符号整数
	 */
	public static final int SHORT = 3;
	/**
	 * 32位有符号字节数字
	 */
	public static final int INT = 4;
	/**
	 * 32位单精度浮点�?
	 */
	public static final int FLOAT = 5;
	/**
	 * 64位双精度浮点�?
	 */
	public static final int DOUBLE = 6;
	/**
	 * 协议类型
	 */
	public static final int PROTOCOL = 7;
	/**
	 * 数组类型
	 */
	public static final int ARRAY = 8;
	/**
	 * 字节�?
	 */
	public static final int BYTEARRAY = 9;
	/**
	 * 无符号short
	 */
	public static final int UNSIGNEDSHORT = 10;

	public static int getObjectLen(Object object) {
		int type = getObjectType(object);
		switch (type) {
		case DataType.ARRAY:
			return 0;
		case DataType.BOOLEAN:
			return 1;
		case DataType.BYTE:
			return 1;
		case DataType.BYTEARRAY:
			return 1;
		case DataType.DOUBLE:
			return 8;
		case DataType.FLOAT:
			return 4;
		case DataType.INT:
			return 4;
			// case DataType.PROTOCOL:
			// return in
		case DataType.SHORT:
			return 2;
		case DataType.UNSIGNEDSHORT:
			return 2;
		case DataType.STRING:
			return 2 + object.toString().length();
		default:
			return 0;
		}
	}

	public static int getObjectType(Object object) {
		if (object instanceof String) {
			return STRING;
		} else if (object instanceof Boolean) {
			return BOOLEAN;
		} else if (object instanceof Byte) {
			return BYTE;
		} else if (object instanceof ByteArray) {
			return BYTEARRAY;
		} else if (object instanceof Short) {
			return SHORT;
		} else if (object instanceof Integer) {
			return INT;
		} else if (object instanceof Float) {
			return FLOAT;
		} else if (object instanceof Double) {
			return DOUBLE;
		} else if (object instanceof Long) {
			return DOUBLE;
		} else if (object instanceof List) {
			return ARRAY;
		}
		return 0;
	}
}
